package com.gsoe.auth.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.gsoe.auth.vo.UserInfoVO;
import com.gsoe.auth.service.UserInfoService;
import com.gsoe.base.model.Result;
import com.gsoe.base.model.User;
import com.gsoe.base.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin()
@RestController()

public class TextController {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    UserInfoService userInfoService;
    @GetMapping("/test/getUserInfo/{id}")
    public Result<UserInfoVO> hello(@PathVariable Long id) {
        return Result.success(userInfoService.getUserInfo(id));
    }

    @RequestMapping("/test/getLoginInfo")
    public Result<User> getLoginInfo(){
        return Result.success(UserUtil.getLoginUser());
    }

    @RequestMapping("/test/r1")
    @SaCheckPermission("test")
    public Result<String> r1(){
        System.out.println(StpUtil.hasPermission("test"));
        return Result.success("该用户拥有test权限");
    }
    @RequestMapping("/test/r1ByRole")
    @SaCheckRole("admin")
    public Result<String> r1ByRole(){
        return Result.success("该用户角色是admin");
    }
}
